<template>
<view class="deliveryBox">
  <search placeholder="客户编码/客户名称/助记符" :debounceTime="500" :val.sync="query.customerName" @change="obtainData"/>
  <scroll-view :style="{height: contentHeight + 'px'}" scroll-y="true"  @scrolltolower="queryData">
    <customer-visit v-for="item in customerList" :data="item" :visitor="visitor"/>
    <end-temp v-show="end"></end-temp>
  </scroll-view>

</view>
</template>

<script>
import search from "@/components/search";
import customerVisit from "../components/customerVisit";
import {getAppBasCustomer} from "../../service/api/delivery";
import {getDistance, getScreen} from "../../service/auth";
import endTemp from "../../components/endTemp";
export default {
  name: "index",
  components:{search, customerVisit, endTemp},
  data(){
    return{
      testData:{
        customerName:'茶山 茶园购物商城(刘黄店)',
        deliveryAddress: '刘黄村委会旁291号',
        distance:'100km'
      },
      query:{
        location:'',
        customerName: '',
        page: 1,
        size: 20
      },
      customerList:[],
      contentHeight:800,
      end:false,
      visitor:0
    }
  },
  onLoad(options){
      this.visitor=options.visitor
  },
  // onLoad(options) {
  //   wx.loadFontFace({
  //     family: 'PingFangSC Medium',
  //     source: 'url("https://www.zjjqf.cn/file/static/PingFangSC-Medium.ttf")',
  //     complete: function (res) { console.log('插入字体'); console.log(res); },
  //     success: function (res) { console.log('成功'); console.log(res); },
  //     fail: function (res) { console.log('失败'); console.log(res); },
  //   })
  //   const screen = getScreen()
  //   this.contentHeight = screen.height - (screen.width/750)*80
  // },
  onShow(){
    const that  = this
    uni.getLocation({
      type: 'wgs84',
        isHighAccuracy:true,
      geocode:true,//设置该参数为true可直接获取经纬度及城市信息
      success: function (res) {
        that.query.location = `${res.longitude},${res.latitude}`;
        that.query.page = 1
        that.customerList = []
        that.onGet()
      },
      fail: function (e) {
        uni.showToast({
          title: '获取地址失败，将导致部分功能不可用',
          icon:'none'
        });
      }})
  },
  created() {
  },
  methods:{
    queryInit(){
      this.query.page= 1
      this.customerList = []
    },
    obtainData(){
      this.queryInit()
      this.onGet()
    },
    queryData(){
      if(this.end)return
      this.query.page++
      this.onGet()
    },
    onGet(){
      getAppBasCustomer(this.query).then(res=>{
        if (res.data.content.length < this.query.size)this.end = true
        this.customerList = this.customerList.concat(res.data.content)
      })
    }
  }
}
</script>

<style scoped>
.deliveryBox{
  padding: 20rpx;
}
</style>
